﻿<Cmdlet(VerbsCommon.Show, "SqlConnection")>
<CmdletBinding(DefaultParameterSetName:="Single")>
Public Class ShowSqlConnection
    Inherits PSCmdlet

    <Parameter(ValueFromPipeline:=True, Position:=0, ParameterSetName:="Single")>
    Public Property ConnectionName As String = "Default"

    <Parameter(Mandatory:=True, ParameterSetName:="All")>
    <[Alias]("ListConnections")>
    Public Property All As SwitchParameter

    Protected Overrides Sub ProcessRecord()
        MyBase.ProcessRecord()

        Select Case ParameterSetName
            Case "All"
                WriteObject(DBInfo.Connections.Keys, True)
            Case "Single"
                If Not DBInfo.Connections.ContainsKey(ConnectionName) Then
                    WriteWarning(DBInfo.NoConnection(ConnectionName))
                Else
                    WriteObject(DBInfo.Connections(ConnectionName).ConnectionInfo)
                End If
        End Select
    End Sub

End Class
